﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Microsoft.ApplicationBlocks.Data;
using System.Data.SqlClient;

namespace DAL
{
    public partial class DBTestDAL
    {
        static string connStr = DAL.Conn.getConnString(DAL.Conn.DataBaseName.DBtest);

        public DBTestDAL()
        { 
        }

        public static DataTable GetList()
        {
            string sql = "select top 20 Id, name, phone, email, address, DateEntered from dbo.e_Employees order by DateEntered DESC";
            return SqlHelper.ExecuteDataset(connStr, System.Data.CommandType.Text, sql).Tables[0];
        }

        public static DataTable GetList(Conn.DataBaseName DBName)
        {
            string TableName = Get1stTableName(DBName);
            string sql = string.Format("SELECT TOP 10 * FROM dbo.{0}", TableName);
            return SqlHelper.ExecuteDataset(Conn.getConnString(DBName), System.Data.CommandType.Text, sql).Tables[0];
        }

        public static string Get1stTableName(Conn.DataBaseName DBName)
        {
            string sql = "SELECT TOP 1 name FROM sys.sysobjects WHERE xtype = 'u' ORDER BY name";
            return SqlHelper.ExecuteDataset(Conn.getConnString(DBName), System.Data.CommandType.Text, sql).Tables[0].Rows[0][0].ToString();
        }


        #region Sql Methods
        
        public int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText)
        {
            return SqlHelper.ExecuteNonQuery(connectionString, commandText, commandText);
        }

        public int ExecuteNonQuery(string connectionString, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
        {
            return SqlHelper.ExecuteNonQuery(connectionString, commandText, commandText, commandParameters);
        }

        #endregion

    }

}
